#include "action.h"
#include "action_history.h"

namespace FD
{
	namespace Action 
	{	
		History::History()
		{
		}

		History::~History()
		{
		}

		void History::apply(Action::Base *action)
		{
			m_redo.RemoveAll();
			m_undo.AddTail( CAutoPtr<Action::Base>(action) );
			action->apply();
		}

		void History::undo()
		{
			ATLASSERT( !m_undo.IsEmpty() );
			CAutoPtr<Action::Base> action = m_undo.RemoveTail();
			action->revert();
			m_redo.AddTail( action );
		}

		void History::redo()
		{
			ATLASSERT( !m_redo.IsEmpty() );
			CAutoPtr<Action::Base> action = m_redo.RemoveTail();
			action->apply();
			m_undo.AddTail( action );
		}
	}
}